package com.ruoyi.web.controller.orecommend.admin;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.OperatorType;
import com.ruoyi.common.utils.OrikaUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.student.domain.OCounselors;
import com.ruoyi.student.domain.OStudent;
import com.ruoyi.student.domain.OStudentInfoe;
import com.ruoyi.student.domain.StudentBaseInfo;
import com.ruoyi.student.domain.vo.*;
import com.ruoyi.student.service.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController("AdminStudentORecommendManageController")
@RequestMapping("/admin/student/orecommend")
public class AdminStudentORecommendManageController extends BaseController {


    @Resource
    private IOStudentService oStudentService;

    @Resource
    private IOStudentInfoeService oStudentInfoeService;

    @Resource
    private IStudentORecommendInfoService studentORecommendInfoService;


    @Resource
    private IOCounselorsService oCounselorsService;


    /**
     * 查询原始推荐表系统中的数据
     *
     * @param vo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('admin:student:orecommend:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentORecommendListSearchVo vo) {
        startPage();
        List<StudentORecommendListVo> list = studentORecommendInfoService.selectStudentRecommendList(vo);
        return getDataTable(list);
    }


    /**
     * 获取单个学生的推荐表信息
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('admin:student:orecommend:info')")
    @GetMapping("/info/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        if (id == null || id == 0L) {
            return error("无效参数");
        }
        StudentORecommendPrintVo vo = new StudentORecommendPrintVo();
        OStudent oStudent = oStudentService.selectOStudentByStudentId(id);
        if (oStudent != null) {
            vo = OrikaUtils.convert(oStudent, StudentORecommendPrintVo.class);
        }
        OStudentInfoe oStudentInfoe = oStudentInfoeService.selectOStudentInfoeByStudentId(id);
        if (oStudentInfoe != null) {
            //TODO 等待优化
            vo.setEmail(oStudentInfoe.getEmail());
            vo.setQQ(oStudentInfoe.getQQ());
            vo.setMobilePhone(oStudentInfoe.getMobilePhone());
            vo.setHomeAddress(oStudentInfoe.getHomeAddress());
            vo.setHomeCode(oStudentInfoe.getHomeCode());
            vo.setHomePhone(oStudentInfoe.getHomePhone());
            vo.setHeight(oStudentInfoe.getHeight());
            vo.setSecondMajor(oStudentInfoe.getSecondMajor());
            vo.setSecondEducation(oStudentInfoe.getSecondEducation());
            vo.setForeignLanguageLevel(oStudentInfoe.getForeignLanguageLevel());
            vo.setComputerLevel(oStudentInfoe.getComputerLevel());
            vo.setLeftVision(oStudentInfoe.getLeftVision());
            vo.setRightVision(oStudentInfoe.getRightVision());
            vo.setJobSearchIntention(oStudentInfoe.getJobSearchIntention());
            vo.setRewardPunishmentPrize1(oStudentInfoe.getRewardPunishmentPrize1());
            vo.setRewardPunishmentPrize2(oStudentInfoe.getRewardPunishmentPrize2());
            vo.setRewardPunishmentPrize3(oStudentInfoe.getRewardPunishmentPrize3());
            vo.setRewardPunishmentPrize4(oStudentInfoe.getRewardPunishmentPrize4());
            vo.setRewardPunishmentPrize5(oStudentInfoe.getRewardPunishmentPrize5());
            vo.setWorkContent1(oStudentInfoe.getWorkContent1());
            vo.setWorkContent2(oStudentInfoe.getWorkContent2());
            vo.setWorkContent3(oStudentInfoe.getWorkContent3());
            vo.setWorkContent4(oStudentInfoe.getWorkContent4());
            vo.setWorkContent5(oStudentInfoe.getWorkContent5());
            vo.setPublishPaper(oStudentInfoe.getPublishPaper());
            vo.setDepartmentOpinion(oStudentInfoe.getDepartmentOpinion());
            vo.setFamilyMember1(oStudentInfoe.getFamilyMember1());
            vo.setFamilyMember2(oStudentInfoe.getFamilyMember2());
            vo.setFamilyMember3(oStudentInfoe.getFamilyMember3());
            vo.setFamilyMember4(oStudentInfoe.getFamilyMember4());
            vo.setFamilyMember5(oStudentInfoe.getFamilyMember5());
            vo.setStudentCheck(oStudentInfoe.getStudentCheck());
            vo.setCounselorCheck(oStudentInfoe.getCounselorCheck());
            vo.setStudentRecommendCheck(oStudentInfoe.getStudentRecommendCheck());
            vo.setCounselorRecommendCheck(oStudentInfoe.getCounselorRecommendCheck());
        }
        if (oStudent != null && oStudent.getStudentId() != null) {
            OCounselors oCounselors = oCounselorsService.selectOCounselorsByCounselorId(oStudent.getCounselorsCounselorid());
            if (oCounselors != null) {
                vo.setCounsellorCode(oCounselors.getCode());
                vo.setCounsellorName(oCounselors.getXm());
                vo.setCounsellorPhone(oCounselors.getPhone());
            }
        }
        return success(vo);
    }


}
